/*
 * Copyright (c) 2010-2011 Plugger Antonio Begue Ponce. All Rights Reserved.
 *
 * This file is part of Plugger Framework.
 *
 *  Plugger Framework is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License version 3 as published by
 *  the Free Software Foundation.
 *
 *  Plugger Framework is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Plugger Framework.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.plugger.data;

/**
 * A class that represent a connection string
 *
 * @author Antonio Begue
 * @version $Revision: 1.0 $
 *
 * @see     DatabaseType
 * @see     ConnectionStringHelper
 * @see     DataConfiguration
 */
public class ConnectionString {
    private DatabaseType databaseType;
    private String user;
    private String password;
    private String database;
    private String server;
    private String provider;

    /**
     * Empty constructor.
     */
    public ConnectionString() {
    }

    /**
     * A ConnectionString constructor that receive all the parameters.
     *
     * @param databaseType the DatabaseType of the connection string.
     * @param username the username of the connection string.
     * @param password the password of the connection string.
     * @param server the server of the connection string.
     * @param database the database of the connection string.
     */
    public ConnectionString(DatabaseType databaseType, String username, String password, String server, String database) {
        this.databaseType = databaseType;
        this.user = username;
        this.password = password;
        this.database = database;
        this.server = server;
        this.provider = ConnectionStringHelper.getProvider(databaseType);
    }

    /**
     * Generates a jdbc connection string.
     *
     * @return a jdbc connection string.
     */
    @Override
    public String toString() {
        return ConnectionStringHelper.generate(getDatabaseType(),user, password, server, database);
    }

    /**
     * Represent the database in use.
     *
     * @return the databaseType
     */
    public DatabaseType getDatabaseType() {
        return databaseType;
    }

    /**
     * Set the database to be used.
     *
     * @param databaseType the databaseType to set
     */
    public void setDatabaseType(DatabaseType databaseType) {
        this.databaseType = databaseType;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

    public String getServer() {
        return server;
    }

    public void setServer(String server) {
        this.server = server;
    }

    public String getProvider() {
        return provider;
    }

    public void setProvider(String provider) {
        this.provider = provider;
    }
}
